/*
 * @Author: 吴让坤
 * @Date: 2023-12-23 14:22:23
 * @LastEditTime: 2023-12-23 16:49:34
 * @Description: 深拷贝
 */
export function deepCopyMap(originalMap: Map<any, any>) {
  const newMap = new Map()

  originalMap.forEach((value, key) => {
    // 如果 value 是一个对象或数组，使用递归调用进行深拷贝
    if (typeof value === 'object' && value !== null) {
      newMap.set(key, deepClone(value))
    }
    else { // 否则直接复制值
      newMap.set(key, value)
    }
  })

  return newMap
}

export function deepClone<T>(obj: T | null): T | null {
  if (obj === null) return null;
  if (typeof obj !== 'object') return obj;

  let copy: any = obj instanceof Date ? new Date(obj) : obj instanceof RegExp ? new RegExp(obj) : {};

  for (let key in obj) {
    if (obj.hasOwnProperty(key)) {
      copy[key] = deepClone(obj[key] as T | null);
    }
  }

  return copy as T | null;
}